package leetcode.每日一题;

import org.junit.Test;

/**
 * @author ：zsy
 * @date ：Created 2023/1/31 6:52 PM
 * @description：https://leetcode.cn/problems/check-if-matrix-is-x-matrix/
 */
public class 判断矩阵是否是一个x矩阵 {
    @Test
    public void test() {

    }

    class Solution {
        public boolean checkXMatrix(int[][] grid) {
            int n = grid.length;
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    int val = grid[i][j];
                    if (i == j || i + j + 1 == n) {
                        if (val == 0) {
                            return false;
                        }
                    } else {
                        if (val != 0) {
                            return false;
                        }
                    }
                }
            }
            return true;
        }
    }
}
